<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Data_customer_model extends CI_Model{
	function __construct() {
		parent::__construct();
	}
	
	function add_data_customer($clause){
		$this->db->insert('data_customer',$clause);
//                die($this->db->last_query());
		return $this->db->insert_id();
	}
        
        function add_customer($clause){
                
		$this->db->insert('customer',$clause);
//                die($this->db->last_query());
		return $this->db->insert_id();
	}
	
	function update_data_customer($data){
		$id = $data['id'];
		unset ($data['id']);
		$this->db->where('id',$id);
		$this->db->update('data_customer',$data);
                return $id;
	}
        
        function update_customer($data){
		$id = $data['id'];
		unset ($data['id']);
		$this->db->where('id',$id);
		$this->db->update('customer',$data);
                return $id;
	}
        
        function delete_customer($id)
        {
            $this->db->delete('customer',array('id' => $id));
        }
	
	function get_data_customer($id){
		$query = $this->db->get_where('data_customer',array('id'=>$id));
		if($query->num_rows>0){
			return $query->row_array();
		}else{
			return FALSE;
		}
	}
        
//        function get_data_customer($id){
//		$query = $this->db->get_where('data_customer',array('id'=>$id));
//		if($query->num_rows>0){
//			return $query->row_array();
//		}else{
//			return FALSE;
//		}
//	}  
        function get_data_customer_clause($clause){
		$query = $this->db->get_where('data_customer',$clause);
		if($query->num_rows>0){
			return $query->row_array();
		}else{
			return FALSE;
		}
	}
        
        function get_customer($id)
        {
            $query = $this->db->get_where('customer',array('id'=>$id));
            if($query->num_rows>0){
                    return $query->row_array();
            }else{
                    return FALSE;
            }
        }
        
        function get_customer_clause($clause){
		$query = $this->db->get_where('customer',$clause);
		if($query->num_rows>0){
			return $query->row_array();
		}else{
			return FALSE;
		}
	}
        
        function get_customer_join_data_clause($clause){
                $this->db->select("*,customer.id AS id_cust");
                $this->db->join("data_customer","data_customer.id=customer.id_data_customer");
		$query = $this->db->get_where('customer',$clause);
                return $query->result_array();
	}
	
	function get_all_data_customer(){
		$query = $this->db->get('data_customer');
		return $query->result_array();
	}
        
        function get_all_customer_clause($clause,$select=''){
                if($select)
                    $this->db->select($select);
		$query = $this->db->get_where('customer',$clause);
//                die($this->db->last_query());
		return $query->result_array();
	}
        
        function delete_data_customer($id)
        {
            $this->db->delete('data_customer',array('id' => $id));
        }
        
        function delete_customer_clause($clause)
        {
            $this->db->delete('customer',$clause);
        }
}

/** End of file */